<template>
  <div class="app-container">
    <el-calendar>
      <!-- 这里使用的是 2.5 slot 语法，对于新项目请使用 2.6 slot 语法-->
      <div
        slot="dateCell"
        slot-scope="{date, data}"
        @click="lookDetail(data.day)">
        <div :class="data.isSelected ? 'is-selected' : ''">
          {{ data.day.split('-').slice(1).join('-') }} {{ data.isSelected ? '✔️' : ''}}
          <div style="display: inline-block" v-for="(item, index) in textContent(data.day)" :key="index">
            <el-tag :type="tagType(item.planStatus)">{{item.planName}}</el-tag>
          </div>
        </div>
      </div>
    </el-calendar>

    <el-dialog title="详情" :visible.sync="show" width="1200px" append-to-body>
      <el-descriptions class="margin-top" :column="3" size="medium" border v-for="(item,index) in detailData" :key="index">
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-user"></i>
            计划名称
          </template>
          {{ item.planName }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-user"></i>
            开始时间
          </template>
          {{ item.startTime }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-user"></i>
            结束时间
          </template>
          {{ item.endTime }}
        </el-descriptions-item>
      </el-descriptions>
    </el-dialog>
  </div>
</template>

<script>
import { listAllPlan } from "@/api/aero/plan";
import { TaskStatus } from "@/enums";

export default {
  data() {
    return {
      planList: [],
      show: false,
      detailData: []
    }
  },
  created() {
    this.getPlanList();
  },
  activated() {
    this.getPlanList();
  },
  methods: {
    PlanStatus() {
      return TaskStatus;
    },
    getPlanList() {
      listAllPlan(null).then(response => {
        this.planList = response.data;
      })
    },
    textContent(date) {
      return this.planList.filter((item) => {
        return item.startTime.substring(0, 10) <= date && item.endTime.substring(0, 10) >= date;
      })
    },
    tagType(planStatus) {
      if (planStatus === this.PlanStatus().NO_START) return 'info';
      if (planStatus === this.PlanStatus().ON_GOING) return 'warning';
      if (planStatus === this.PlanStatus().FINISHED) return 'success';
      if (planStatus === this.PlanStatus().PAUSED) return 'info';
      if (planStatus === this.PlanStatus().DEPRECATED) return 'danger';
    },
    lookDetail(date) {
      this.detailData = this.textContent(date);
      this.show = true;
    }
  }
}
</script>

<style>
.is-selected {
  color: #1989FA;
}
</style>
